package lp.xian.materials.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import lp.xian.materials.vo.QualityRawVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import lp.xian.materials.domain.QualityRaw;
import lp.xian.materials.service.IQualityRawService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 原料质检Controller
 *
 * @author ruoyi
 * @date 2023-08-15
 */
@RestController
@RequestMapping("/raw/raw")
public class QualityRawController extends BaseController
{
    @Autowired
    private IQualityRawService qualityRawService;

    /**
     * 查询原料质检列表
     */
    @PreAuthorize("@ss.hasPermi('raw:raw:list')")
    @GetMapping("/list")
    public TableDataInfo list(QualityRaw qualityRaw)
    {
        startPage();
        List<QualityRaw> list = qualityRawService.selectQualityRawList(qualityRaw);
        return getDataTable(list);
    }

    /**
     * 导出原料质检列表
     */
    @PreAuthorize("@ss.hasPermi('raw:raw:export')")
    @Log(title = "原料质检", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QualityRaw qualityRaw)
    {
        List<QualityRaw> list = qualityRawService.selectQualityRawList(qualityRaw);
        ExcelUtil<QualityRaw> util = new ExcelUtil<QualityRaw>(QualityRaw.class);
        util.exportExcel(response, list, "原料质检数据");
    }

    /**
     * 获取原料质检详细信息
     */
    @PreAuthorize("@ss.hasPermi('raw:raw:query')")
    @GetMapping(value = "/{qualityRawId}")
    public AjaxResult getInfo(@PathVariable("qualityRawId") Integer qualityRawId)
    {
        return success(qualityRawService.selectQualityRawByQualityRawId(qualityRawId));
    }

    /**
     * 新增原料质检
     */
    @PreAuthorize("@ss.hasPermi('raw:raw:add')")
    @Log(title = "原料质检", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QualityRaw qualityRaw)
    {
        return toAjax(qualityRawService.insertQualityRaw(qualityRaw));
    }

    /**
     * 修改原料质检
     */
    @PreAuthorize("@ss.hasPermi('raw:raw:edit')")
    @Log(title = "原料质检", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QualityRawVo qualityRawvo)
    {
        return toAjax(qualityRawService.updateQualityRaw(qualityRawvo));
    }

    /**
     * 删除原料质检
     */
    @PreAuthorize("@ss.hasPermi('raw:raw:remove')")
    @Log(title = "原料质检", businessType = BusinessType.DELETE)
    @DeleteMapping("/{qualityRawIds}")
    public AjaxResult remove(@PathVariable Integer[] qualityRawIds)
    {
        return toAjax(qualityRawService.deleteQualityRawByQualityRawIds(qualityRawIds));
    }
}
